<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>角色死亡日志</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" name="search" lay-filter="table-search" id="search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">选择区服:</label>
                            <div class="layui-input-inline">
                                <select name="gameArea" class="layui-select">
                                    <option v-for="(item,index) in services" :value="item.server_id" :selected="index==0">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">场景:</label>
                            <div class="layui-input-inline">
                                <select name="map_id" class="layui-select" lay-search>
                                    <option value="">--请选择--</option>
                                    <option v-for="(item,index) in mapList" :value="item.id">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">击杀者类型:</label>
                            <div class="layui-input-inline">
                                <select name="kill_type" class="layui-select" >
                                    <option value="">--请选择--</option>
                                    <option value="1">玩家</option>
                                    <option value="0">NPC</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">账号ID:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="memId" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">角色ID:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="roleId" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">角色名:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="nick" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">击杀者ID:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="kill_id" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">记录时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="createDateBegin" id="createTime0"
                                       placeholder="开始时间" autocomplete="off" class="layui-input" />
                                <input type="text" name="createDateEnd" id="createTime1"
                                       placeholder="截止时间" autocomplete="off" class="layui-input" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>

        </fieldset>
        <script type="text/html" id="topToolBar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export" >导出</button>
                </div>
            </div>
        </script>
        <table class="layui-hide" id="current-table" lay-filter="current-table"></table>
        <script type="text/html" id="currentTableBar">
        </script>



    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
var mapList = getEnum('map');

new Vue({
    el: "#search",
    data: {
        services: JSON.parse(localStorage.getItem('services')),
        mapList:mapList,
    },
    created() {

    },
    updated() {

    },
    mounted() {

        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;
                 laydate=layui.laydate;

            laydate.render({
                elem: '#createTime0',
                value: getYmd(0)
            });
            laydate.render({
                elem: '#createTime1',
                value: getYmd(1)
            })

            table.render({
                elem: '#current-table',
                url: "/admin/logRoleDeath/paginate",
                where:form.val("table-search"),
                toolbar: '#topToolBar',
                defaultToolbar: ['filter'],
                cols: [[

                    {field: "logTime", title: "日志生成时间",templet(row){
                            return getYMDHMS(row.logTime)
                        }},
                    {field: "line", title: "所在线"},
                    {field: "serverId", title: "所在服务器ID"},
                    {field: "memId", title: "账号ID"},
                    {field: "roleId", title: "角色ID"},
                    {field: "nick", title: "角色昵称"},
                    {field: "kill_type", title: "击杀者类型",templet:function(row){
                            var values = [{"value":1,"title":"玩家"},{"value":0,"title":"NPC"}];
                            var value = row.kill_type;
                            for(var k in values){
                                if(value === values[k].value ){
                                    return values[k].title
                                }
                            }
                            return row.kill_type;
                        }},
                    {field: "kill_id", title: "击杀者ID"},
                    {field: "kill_nick", title: "击杀者名称"},
                    {field: "map_id", title: "场景",templet(row){
                            for(var k in mapList){
                                if(mapList[k].id == row.map_id){
                                    return mapList[k].name;
                                }
                            }
                            return mapList[k].id;
                        }},

                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });
            form.on('submit(data-search-btn)', function (data) {
                var searchData = data.field;
                //执行搜索重载
                table.reload('current-table', {
                    page: { curr : 1 }
                    , where:searchData
                }, 'data');
                return false;
            });
            table.on('toolbar(current-table)', function (obj) {
                if (obj.event === 'insert') {
                    layer.open({
                        title: "角色死亡日志-添加",
                        type: 2,
                        shade: 0.2,
                        maxmin:true,
                        shadeClose: true,
                        area: ['700px', '500px'],
                        content: 'form.html',
                    });
                } else {
                    console.log(1)
                }
            });

            table.on('tool(current-table)', function (obj) {
                if (obj.event === 'update') {
                    layer.open({
                        title: "角色死亡日志-编辑",
                        type: 2,
                        shade: 0.2,
                        maxmin:true,
                        shadeClose: true,
                        area: ['700px', '500px'],
                        content: 'form.html?id='+obj.data.id,
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    var delPop = layer.confirm('确定要删除吗?',{title:"提示",icon:3},function(){
                        $.post("/admin/logRoleDeath/"+obj.data.id,{_method:'delete'},function (res) {
                            if (res.code === 0){
                                layer.msg('删除成功',{icon:1,time:500},function(){
                                    table.reload('current-table');
                                })
                                table.reload()
                                layer.close(delPop)
                            } else {
                                layer.msg(res.msg,{icon:2})
                            }
                        });
                    })
                }
            });



            table.on('toolbar(current-table)', function (obj) {
                if(obj.event === 'export'){ //导出
                    var searchData = form.val('table-search');
                    searchData.page = 1;
                    searchData.limit = 9999999;
                    var layerIndex = layer.msg("请求中请耐心等待...",{icon:16,time:999999999});
                    $.get('/admin/logRoleDeath/export',searchData,function(res){
                        layer.close(layerIndex)
                        browserDownload("/" + res.data);
                    });
                }
            });
        });
    }
})
</script>
</body>
</html>
